package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.car.actionform.CarStockModifyForm;
import com.tianqu.tms.www.car.controller.CarStockModifyController;
import com.tianqu.tms.www.car.controller.CarStockModifyResultController;
import com.tianqu.tms.www.car.viewhelper.CarStockModifyViewhelper;

public class CarStockModifyPicResultAction extends TmsAction{
	private static final String LOADIMG = "imgLoad";//跳转到图片上传
	private static final String IMGKEY = "imgKey";// 图片位置
	private static final String IMGTYPE = "imgType";// 图片类型
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response, UserContext uc) throws Exception {
		CarStockModifyForm inputForm = (CarStockModifyForm)form; 
		String forward = "";
		
		//
		CarStockModifyViewhelper viewhelper = new CarStockModifyViewhelper();
		viewhelper = (CarStockModifyViewhelper)uc.getAttribute(VIEWHELP);
		viewhelper.setPhoto_1(inputForm.getImg1());
		viewhelper.setPhoto_2(inputForm.getImg2());
		viewhelper.setPhoto_3(inputForm.getImg3());
		viewhelper.setPhoto_4(inputForm.getImg4());
		viewhelper.setPhoto_5(inputForm.getImg5());
		viewhelper.setPhoto_6(inputForm.getImg6());
		viewhelper.setPhoto_7(inputForm.getImg7());
		viewhelper.setPhoto_8(inputForm.getImg8());
		
		//
		if(inputForm.getImgUpLoad1()!=null)
		{
			//往viewhelp中放一个值
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "1");
			forward = LOADIMG;
		}else  if(inputForm.getImgUpLoad2()!=null)
		{
			//往viewhelp中放一个值
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "2");
			forward = LOADIMG;
		}else  if(inputForm.getImgUpLoad3()!=null)
		{
			//往viewhelp中放一个值
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "3");
			forward = LOADIMG;
		}else  if(inputForm.getImgUpLoad4()!=null)
		{
			//往viewhelp中放一个值
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "4");
			forward = LOADIMG;
		}else  if(inputForm.getImgUpLoad5()!=null)
		{
			//往viewhelp中放一个值
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "5");
			forward = LOADIMG;
		}else  if(inputForm.getImgUpLoad6()!=null)
		{
			//往viewhelp中放一个值
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "6");
			forward = LOADIMG;
		}else  if(inputForm.getImgUpLoad7()!=null)
		{
			//往viewhelp中放一个值
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "7");
			forward = LOADIMG;
		}else  if(inputForm.getImgUpLoad8()!=null) {
			//往viewhelp中放一个值
			uc.setAttribute(IMGTYPE, "1");
			uc.setAttribute(IMGKEY, "8");
			forward = LOADIMG;
		}else{//save
			CarStockModifyResultController controller = new CarStockModifyResultController();
			controller.executeModifyPic(uc);
			//get info
//			CarStockModifyController indexController = new CarStockModifyController();
//			indexController.execute(uc);
//			request.setAttribute(TmsConstants.VIEWHELP, (CarStockModifyViewhelper) uc.getAttribute(TmsConstants.VIEWHELP));
			forward = TmsConstants.SUCCESS;
		}
		return mapping.findForward(forward);
	}

}
